//
// Created by sjjmw on 3/24/2022.
//

//应该使用dfs

#include "iostream"
#include "vector"
#include "list"
#include "algorithm"
#include "string"
#include "unordered_map"
#include "cmath"
#include<iomanip>
#include "string"
#include "map"
#include "list"
struct Range{
    int r;
    int l;
};
bool cmp(Range&r1,Range&r2){
    if(r1.l==r2.l){
        return r1.r<r2.r;
    }
    return r1.l<r2.l;
}
struct Sol{
    std::vector<Range> ranges;
    void handle(
            int n
            ){
        ranges.reserve(n);
        for(int i=0;i<n;i++){
            Range r;
            std::cin>>r.l>>r.r;
            ranges.push_back(r);
        }
        std::sort(ranges.begin(),ranges.end(), cmp);
        int right=ranges[0].r;
        int ans=0;
        for(int i=1;i<ranges.size();i++){
            if(ranges[i].l<right){
                //重叠了，删区间，删的得是右边更大的区间
                if(ranges[i].r<right){
                    right=ranges[i].r;
                }
                ans++;
            }else{
                right=ranges[i].r;
            }
        }
        printf("%d\n",ans);
    }
};
int main(){
    int a,b,c;
//    float a,b,c,d;
    int e;
    while(std::cin>>a){
        Sol().handle(a);
    }

    return 0;
}